package 剑指Offer专项突破;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author zhang lei
 * @Date 2022-05-04 12:39
 */
public class Algo058 {
    public static void main(String[] args) {
        MyCalendar myCalendar = new MyCalendar();
        System.out.println(myCalendar.book(10,20));
        System.out.println(myCalendar.book(15,25));
        System.out.println(myCalendar.book(20,30));

        System.out.println(String.format("模板项: 【%s】 不能为空", "解决未解决"));
    }

}

class MyCalendar {

    List<Integer[]> ends;

    public MyCalendar() {
        ends = new ArrayList<>();
    }

    /**
     * 预定
     * @param start
     * @param end
     * @return
     */
    public boolean book (int start, int end) {
        if(ends.size()<1) {
            ends.add(new Integer[]{start, end});
            return true;
        }

        boolean flag = true;
        for (Integer[] integers : ends) {
            int left = integers[0];
            int right = integers[1];
            if(start >= right || end<=left){
                continue;
            }else {
                flag = false;
            }
        }

        if(flag) {
            ends.add(new Integer[]{start, end});
        }
        return flag;
    }
}
